using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using MetaObjects.Contracts;

namespace MetaObjects.Core
{
	public class MetaDataRow : IMetaEntity<DataRow>
	{
		public object Key { get; private set; }
		public string InternalName { get; private set; }
		public string DisplayName { get; set; }
		public string Description { get; set; }
		public IEntityCollection<IMetaField> MetaFields { get; private set; }
		public Func<DataRow> Factory { get; private set; }
		Func<object> IMetaEntity.Factory
		{
			get { return () => Factory(); }
		}

		//public Func<DataTable, object> KeyAccessor { get; set; }
		//Func<object, object> IMetaEntity.KeyAccessor { get; set; }

		public MetaDataRow(object key, string internalName, Func<DataRow> factory)
		{
			Key = key;
			InternalName = internalName;
			MetaFields = new EntityCollection<IMetaField>();
			Factory = factory;
		}

		public MetaDataRow(object key, string internalName, Func<DataRow> factory, IEnumerable<IMetaField> metaFields)
		{
			Key = key;
			InternalName = internalName;
			MetaFields = new EntityCollection<IMetaField>(metaFields);
			Factory = factory;
		}
	}
}